package cn.uce.cc.srv.biz.impl;


import cn.uce.base.page.Page;
import cn.uce.base.page.Pagination;
import cn.uce.cc.api.service.biz.ICcWoCustSerBiz;

import cn.uce.cc.srv.service.CcWoCustSerService;
import cn.uce.ics.base.entity.cs.CsWoCustSer;
import cn.uce.ics.base.entity.cs.CsWoWorkOrder;
import cn.uce.ics.base.vo.cs.CsWoCustSerVo;
import cn.uce.ics.base.vo.srv.CcRequestVo;
import cn.uce.service.biz.ICreateWoSerOrderBiz;
import cn.uce.service.biz.IWoOrderQueryBiz;
import cn.uce.web.common.base.CurrentUser;
import com.alibaba.fastjson.JSON;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Map;

/**
   * @Author liupan
   * @Description 
   * @Date  2020-05-08 11:03
   */
@Service("ccWoCustSerBiz")
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS, rollbackFor = Exception.class)
public class CcWoCustSerBiz implements ICcWoCustSerBiz {
    private static final Logger log = LoggerFactory.getLogger(CcSmsMessageBiz.class);

    @Resource
    ICreateWoSerOrderBiz createWoSerOrderBiz;

    @Resource
    CcWoCustSerService ccWoCustSerService;


    @Resource
    IWoOrderQueryBiz woOrderQueryBiz;

    /**
     * 客服工单提交
     * @param csWoCustSer
     * @param csWoWorkOrder
     * @param currentUser
     * @return
     */
    @Override
    public Map<String, Object> submit(CsWoCustSer csWoCustSer, CsWoWorkOrder csWoWorkOrder, CurrentUser currentUser) {
        Map<String, Object> returnMap = null;
        csWoCustSer.setSource(0);
        try {
            log.warn("ccWoCustSerBiz:submit,csWoCustSer:"+JSON.toJSONString(csWoCustSer)
                    +",csWoWorkOrder"+JSON.toJSONString(csWoWorkOrder)+",currentUser:"+JSON.toJSONString(currentUser));
            returnMap = createWoSerOrderBiz.createOrderFromCallCenter(csWoCustSer, csWoWorkOrder, currentUser);
            log.warn("ccWoCustSerBiz:return"+ JSON.toJSONString(returnMap));
        } catch (Exception e) {
            log.error("ccWoCustSerBiz:submit",e);
        }
        return returnMap;
    }

    @Override
    public Map<String,Object> getCsWoCustSerVoLists(CsWoCustSerVo csWoCustSerVo, Page page) {
        CcRequestVo<CsWoCustSerVo> vo = new CcRequestVo<CsWoCustSerVo>();
        vo.setData(csWoCustSerVo);
        vo.setPage(page);
        Map<String, Object> returnMap = null;
        try {
            returnMap = woOrderQueryBiz.getCsWoCustSerVoList(vo);
        } catch (Exception e) {
            log.error("ccWoCustSerBiz:getCsWoCustSerVoLists",e);
        }
        return returnMap;
    }

    @Override
    public Map<String, Object> getFirstNodeDealOrg(String wayBillNum, Long orderChilType, int source) {
        Map<String, Object> returnMap = null;
        try {
            returnMap = createWoSerOrderBiz.getFirstNodeDealOrg(wayBillNum,orderChilType,source);
        } catch (Exception e) {
            log.error("ccWoCustSerBiz:getFirstNodeDealOrg",e);
        }
        return returnMap;
    }

    @Override
    public int checkSameCsWoCustSer(CsWoCustSerVo csWoCustSerVo) {
        int returnCount = 0;
        try {
            returnCount = createWoSerOrderBiz.checkSameCsWoCustSer(csWoCustSerVo);
        } catch (Exception e) {
            log.error("ccWoCustSerBiz:checkSameCsWoCustSer",e);
        }
        return returnCount;
    }

    @Override
    public int checkCanCreate(String wayBillNum, Long orderChilType, int source) {
        int returnCount = 0;
        try {
            returnCount = createWoSerOrderBiz.checkCanCreate(wayBillNum,orderChilType,source);
        } catch (Exception e) {
            log.error("ccWoCustSerBiz:checkCanCreate",e);
        }
        return returnCount;
    }

    @Override
    public int checkRequireWayBillNum(Long orderType, Long orderChilType, int source) {
        int returnCount = 0;
        try {
            returnCount = createWoSerOrderBiz.checkRequireWayBillNum(orderType,orderChilType,source);
        } catch (Exception e) {
            log.error("ccWoCustSerBiz:checkRequireWayBillNum",e);
        }
        return returnCount;
    }

    @Override
    public int checkManualSelMechanism(Long orderChilType, int source) {
        int returnCount = 0;
        try {
            returnCount = createWoSerOrderBiz.checkManualSelMechanism(orderChilType,source);
        } catch (Exception e) {
            log.error("ccWoCustSerBiz:checkManualSelMechanism",e);
        }
        return returnCount;
    }


}
